# 姓名:刘豹
#  开发时间: 2021/5/21 13:31
from feature import features
from sklearn.svm import LinearSVC
import numpy as np
X_train=features('D:\python\workspace\insects_detection\processed_imgs\\5-1-1-A.jpg')
y_train=np.array([0,0,0,1,1,0,1,0,1,1,1,1,1,1,1,0,0,0,0,1,1,0,1,1,0,1,0,0,0,1,1,1,0,0,0,0,1,0
                  ,1,1,1,0,1,1,1,1,1,0,1,0,0,1,1,0,0,0,0,1,0,0,0,0,1,0,1,0,0,0,0,1,0,1,0,1,0,1
                  ,0,0,0,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,0,1,1,1,1,1,1,1,0,1,1,1,1,1,0,1,1,1,0,0,1
                  ,0,1,1,1,0,1,1,1,1,1,1,1,1,1,1,0,1,1,1,0,1,0,0,1,0,1,1,0,1,1,0,1,0,1,0,1,0,1,0
                  ,1,1,1,0,1,0,1,1,1,0,0,0,1,1,1,0,1,0,1,0,1,1,1,0,1,0,1,1,1,1,1,1,1,1,0,1,1,0,0,0,1
                  ,1,0,0,1,0,0,1,0,0,1,1,1,0,0,1,1,1,1,1,0,1,1,0,1,1,0,1,1,1,0,1])
min_on_training=X_train.min(axis=0)
range_on_training=(X_train-min_on_training).max(axis=0)
X_train_scaled=(X_train-min_on_training)/range_on_training

model=LinearSVC(max_iter=100000,C=150)
model.fit(X_train_scaled,y_train)
X_test=features('test3.jpg')
y_test=np.array([1,1,0,1,0,1,1,1,0,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,0,1,0,1,1,0,1,0,1,1
                 ,0,1,1,0,0,1,1,1,1,1,0,0,1,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1
                 ,1,1,1,0,1,1,0,1,1,1,1,1,1,1,1,0,1,0,0,1,1,1,1,1,1,1,1
                 ,1,1,1,1,1,1,1,1,1,1,0,1,1,1,1,1,1,1,1])
X_test_scaled=(X_test-min_on_training)/range_on_training
print(model.score(X_train_scaled,y_train))
print(model.score(X_test_scaled,y_test))





